//
//  BPControllerTool.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/7/27.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "BPControllerTool.h"
#import "NFViewController.h"
#import "BPHomeViewController.h"
#import "BPNavigationController.h"

@implementation BPControllerTool

+ (void)chooseRootViewController
{
    //拿到上次用户使用版本记录和这次比较
    //把每次打开的版本记录到沙盒
    //从沙盒中取出上次存储的版本号
    NSString *versionKey = (__bridge NSString *) kCFBundleVersionKey;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *lastVersion = [defaults objectForKey:versionKey];
    //获取当前版本号
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[versionKey];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if ([currentVersion isEqualToString:lastVersion]) {
        BPHomeViewController *home = [[BPHomeViewController alloc] init];
        BPNavigationController *nav = [[BPNavigationController alloc] initWithRootViewController:home];
        window.rootViewController = nav;
    }else{
        window.rootViewController = [[NFViewController alloc] init];
        //存储本次版本号
        [defaults setObject:currentVersion forKey:versionKey];
        [defaults synchronize];
    }
}

@end
